

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>pyamp.ui.input.userInput &mdash; pyamp v1.2 documentation</title>
    <link rel="stylesheet" href="../../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../../',
        VERSION:     '1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
    <link rel="top" title="pyamp v1.2 documentation" href="../../../../index.html" />
    <link rel="up" title="pyamp.ui.input" href="../input.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../../../index.html">pyamp v1.2 documentation</a> &raquo;</li>
          <li><a href="../../../index.html" >Module code</a> &raquo;</li>
          <li><a href="../input.html" accesskey="U">pyamp.ui.input</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for pyamp.ui.input.userInput</h1><div class="highlight"><pre>
<span class="c"># Copyright 2012 Brett Ponsler</span>
<span class="c"># This file is part of pyamp.</span>
<span class="c">#</span>
<span class="c"># pyamp is free software: you can redistribute it and/or modify</span>
<span class="c"># it under the terms of the GNU General Public License as published by</span>
<span class="c"># the Free Software Foundation, either version 3 of the License, or</span>
<span class="c"># (at your option) any later version.</span>
<span class="c">#</span>
<span class="c"># pyamp is distributed in the hope that it will be useful,</span>
<span class="c"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="c"># GNU General Public License for more details.</span>
<span class="c">#</span>
<span class="c"># You should have received a copy of the GNU General Public License</span>
<span class="c"># along with pyamp.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="sd">&#39;&#39;&#39;The userInput module contains the UserInput class which provides</span>
<span class="sd">the ability to process keyboard presses from a user and call a specific</span>
<span class="sd">function when certain keys are received.</span>

<span class="sd">&#39;&#39;&#39;</span>
<span class="kn">from</span> <span class="nn">copy</span> <span class="kn">import</span> <span class="n">copy</span>

<span class="kn">from</span> <span class="nn">pyamp.ui.input.evdev</span> <span class="kn">import</span> <span class="n">Device</span>


<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s">&quot;UserInput&quot;</span><span class="p">]</span>


<span class="c"># Function for determining if a list item is not the given value</span>
<span class="n">_NOT_FUNCTION</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">value</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">item</span><span class="p">:</span> <span class="n">item</span> <span class="o">!=</span> <span class="n">value</span>


<div class="viewcode-block" id="UserInput"><a class="viewcode-back" href="../../../../_generated/pyamp_ui_input_userInput.html#pyamp.ui.input.userInput.UserInput">[docs]</a><span class="k">class</span> <span class="nc">UserInput</span><span class="p">:</span>
    <span class="sd">&#39;&#39;&#39;The UserInput class uses the :mod:`amp.ui.input.evdev` module to</span>
<span class="sd">    receive the user&#39;s keyboard presses given the specific Linux</span>
<span class="sd">    keyboard device.</span>

<span class="sd">    This class provides to ability to add a series of callbacks for</span>
<span class="sd">    specific keyboard presses. These functions will be called in the</span>
<span class="sd">    event that the key presses occur.</span>

<span class="sd">    &#39;&#39;&#39;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">keyboard</span><span class="p">,</span> <span class="n">debug</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        * keyboard -- The Linux keyboard device</span>
<span class="sd">        * debug -- True for debugging mode, False otherwise</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__dev</span> <span class="o">=</span> <span class="n">Device</span><span class="p">(</span><span class="n">keyboard</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__debug</span> <span class="o">=</span> <span class="n">debug</span>

        <span class="c"># Key for alphanumeric keys, punctuation, and any key</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_ALPHA_NUMERIC</span> <span class="o">=</span> <span class="s">&quot;KEY_ALPHANUMERIC&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PUNCTUATION</span> <span class="o">=</span> <span class="s">&quot;KEY_PUNCTUATION&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_ANY</span> <span class="o">=</span> <span class="s">&quot;KEY_ANY&quot;</span>

        <span class="c"># Define control modifiers</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_CTRL</span> <span class="o">=</span> <span class="s">&quot;MOD_CTRL&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_LEFTCTRL</span> <span class="o">=</span> <span class="s">&quot;KEY_LEFTCTRL&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_RIGHTCTRL</span> <span class="o">=</span> <span class="s">&quot;KEY_RIGHTCTRL&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_LEFTRIGHTCTRL</span> <span class="o">=</span> <span class="s">&quot;MOD_LEFTRIGHTCTRL&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_ALT</span> <span class="o">=</span> <span class="s">&quot;MOD_ALT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_LEFTALT</span> <span class="o">=</span> <span class="s">&quot;KEY_LEFTALT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_RIGHTALT</span> <span class="o">=</span> <span class="s">&quot;KEY_RIGHTALT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_LEFTRIGHTALT</span> <span class="o">=</span> <span class="s">&quot;MOD_LEFTRIGHTALT&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_SHIFT</span> <span class="o">=</span> <span class="s">&quot;MOD_SHIFT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_LEFTSHIFT</span> <span class="o">=</span> <span class="s">&quot;KEY_LEFTSHIFT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_RIGHTSHIFT</span> <span class="o">=</span> <span class="s">&quot;KEY_RIGHTSHIFT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_LEFTRIGHTSHIFT</span> <span class="o">=</span> <span class="s">&quot;MOD_LEFTRIGHTSHIFT&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_META</span> <span class="o">=</span> <span class="s">&quot;MOD_META&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_LEFTMETA</span> <span class="o">=</span> <span class="s">&quot;KEY_LEFTMETA&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_RIGHTMETA</span> <span class="o">=</span> <span class="s">&quot;KEY_RIGHTMETA&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">MOD_LEFTRIGHTMETA</span> <span class="o">=</span> <span class="s">&quot;MOD_LEFTRIGHTMETA&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_ESC</span> <span class="o">=</span> <span class="s">&quot;KEY_ESC&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_1</span> <span class="o">=</span> <span class="s">&quot;KEY_1&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_2</span> <span class="o">=</span> <span class="s">&quot;KEY_2&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_3</span> <span class="o">=</span> <span class="s">&quot;KEY_3&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_4</span> <span class="o">=</span> <span class="s">&quot;KEY_4&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_5</span> <span class="o">=</span> <span class="s">&quot;KEY_5&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_6</span> <span class="o">=</span> <span class="s">&quot;KEY_6&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_7</span> <span class="o">=</span> <span class="s">&quot;KEY_7&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_8</span> <span class="o">=</span> <span class="s">&quot;KEY_8&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_9</span> <span class="o">=</span> <span class="s">&quot;KEY_9&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_0</span> <span class="o">=</span> <span class="s">&quot;KEY_0&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_MINUS</span> <span class="o">=</span> <span class="s">&quot;KEY_MINUS&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_EQUAL</span> <span class="o">=</span> <span class="s">&quot;KEY_EQUAL&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_BACKSPACE</span> <span class="o">=</span> <span class="s">&quot;KEY_BACKSPACE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_TAB</span> <span class="o">=</span> <span class="s">&quot;KEY_TAB&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_Q</span> <span class="o">=</span> <span class="s">&quot;KEY_Q&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_W</span> <span class="o">=</span> <span class="s">&quot;KEY_W&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_E</span> <span class="o">=</span> <span class="s">&quot;KEY_E&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_R</span> <span class="o">=</span> <span class="s">&quot;KEY_R&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_T</span> <span class="o">=</span> <span class="s">&quot;KEY_T&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_Y</span> <span class="o">=</span> <span class="s">&quot;KEY_Y&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_U</span> <span class="o">=</span> <span class="s">&quot;KEY_U&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_I</span> <span class="o">=</span> <span class="s">&quot;KEY_I&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_O</span> <span class="o">=</span> <span class="s">&quot;KEY_O&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_P</span> <span class="o">=</span> <span class="s">&quot;KEY_P&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LEFTBRACE</span> <span class="o">=</span> <span class="s">&quot;KEY_LEFTBRACE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_RIGHTBRACE</span> <span class="o">=</span> <span class="s">&quot;KEY_RIGHTBRACE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_ENTER</span> <span class="o">=</span> <span class="s">&quot;KEY_ENTER&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LEFTCTRL</span> <span class="o">=</span> <span class="s">&quot;KEY_LEFTCTRL&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_A</span> <span class="o">=</span> <span class="s">&quot;KEY_A&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_S</span> <span class="o">=</span> <span class="s">&quot;KEY_S&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_D</span> <span class="o">=</span> <span class="s">&quot;KEY_D&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F</span> <span class="o">=</span> <span class="s">&quot;KEY_F&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_G</span> <span class="o">=</span> <span class="s">&quot;KEY_G&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_H</span> <span class="o">=</span> <span class="s">&quot;KEY_H&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_J</span> <span class="o">=</span> <span class="s">&quot;KEY_J&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_K</span> <span class="o">=</span> <span class="s">&quot;KEY_K&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_L</span> <span class="o">=</span> <span class="s">&quot;KEY_L&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_SEMICOLON</span> <span class="o">=</span> <span class="s">&quot;KEY_SEMICOLON&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_APOSTROPHE</span> <span class="o">=</span> <span class="s">&quot;KEY_APOSTROPHE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_GRAVE</span> <span class="o">=</span> <span class="s">&quot;KEY_GRAVE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LEFTSHIFT</span> <span class="o">=</span> <span class="s">&quot;KEY_LEFTSHIFT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_BACKSLASH</span> <span class="o">=</span> <span class="s">&quot;KEY_BACKSLASH&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_Z</span> <span class="o">=</span> <span class="s">&quot;KEY_Z&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_X</span> <span class="o">=</span> <span class="s">&quot;KEY_X&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_C</span> <span class="o">=</span> <span class="s">&quot;KEY_C&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_V</span> <span class="o">=</span> <span class="s">&quot;KEY_V&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_B</span> <span class="o">=</span> <span class="s">&quot;KEY_B&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_N</span> <span class="o">=</span> <span class="s">&quot;KEY_N&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_M</span> <span class="o">=</span> <span class="s">&quot;KEY_M&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_COMMA</span> <span class="o">=</span> <span class="s">&quot;KEY_COMMA&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_DOT</span> <span class="o">=</span> <span class="s">&quot;KEY_DOT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_SLASH</span> <span class="o">=</span> <span class="s">&quot;KEY_SLASH&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_RIGHTSHIFT</span> <span class="o">=</span> <span class="s">&quot;KEY_RIGHTSHIFT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KPASTERISK</span> <span class="o">=</span> <span class="s">&quot;KEY_KPASTERISK&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LEFTALT</span> <span class="o">=</span> <span class="s">&quot;KEY_LEFTALT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_SPACE</span> <span class="o">=</span> <span class="s">&quot;KEY_SPACE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_CAPSLOCK</span> <span class="o">=</span> <span class="s">&quot;KEY_CAPSLOCK&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F1</span> <span class="o">=</span> <span class="s">&quot;KEY_F1&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F2</span> <span class="o">=</span> <span class="s">&quot;KEY_F2&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F3</span> <span class="o">=</span> <span class="s">&quot;KEY_F3&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F4</span> <span class="o">=</span> <span class="s">&quot;KEY_F4&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F5</span> <span class="o">=</span> <span class="s">&quot;KEY_F5&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F6</span> <span class="o">=</span> <span class="s">&quot;KEY_F6&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F7</span> <span class="o">=</span> <span class="s">&quot;KEY_F7&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F8</span> <span class="o">=</span> <span class="s">&quot;KEY_F8&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F9</span> <span class="o">=</span> <span class="s">&quot;KEY_F9&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F10</span> <span class="o">=</span> <span class="s">&quot;KEY_F10&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_NUMLOCK</span> <span class="o">=</span> <span class="s">&quot;KEY_NUMLOCK&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_SCROLLLOCK</span> <span class="o">=</span> <span class="s">&quot;KEY_SCROLLLOCK&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KP7</span> <span class="o">=</span> <span class="s">&quot;KEY_KP7&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KP8</span> <span class="o">=</span> <span class="s">&quot;KEY_KP8&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KP9</span> <span class="o">=</span> <span class="s">&quot;KEY_KP9&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KPMINUS</span> <span class="o">=</span> <span class="s">&quot;KEY_KPMINUS&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KP4</span> <span class="o">=</span> <span class="s">&quot;KEY_KP4&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KP5</span> <span class="o">=</span> <span class="s">&quot;KEY_KP5&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KP6</span> <span class="o">=</span> <span class="s">&quot;KEY_KP6&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KPPLUS</span> <span class="o">=</span> <span class="s">&quot;KEY_KPPLUS&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KP1</span> <span class="o">=</span> <span class="s">&quot;KEY_KP1&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KP2</span> <span class="o">=</span> <span class="s">&quot;KEY_KP2&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KP3</span> <span class="o">=</span> <span class="s">&quot;KEY_KP3&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KP0</span> <span class="o">=</span> <span class="s">&quot;KEY_KP0&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KPDOT</span> <span class="o">=</span> <span class="s">&quot;KEY_KPDOT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_103RD</span> <span class="o">=</span> <span class="s">&quot;KEY_103RD&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F13</span> <span class="o">=</span> <span class="s">&quot;KEY_F13&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_102ND</span> <span class="o">=</span> <span class="s">&quot;KEY_102ND&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F11</span> <span class="o">=</span> <span class="s">&quot;KEY_F11&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F12</span> <span class="o">=</span> <span class="s">&quot;KEY_F12&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F14</span> <span class="o">=</span> <span class="s">&quot;KEY_F14&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F15</span> <span class="o">=</span> <span class="s">&quot;KEY_F15&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F16</span> <span class="o">=</span> <span class="s">&quot;KEY_F16&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F17</span> <span class="o">=</span> <span class="s">&quot;KEY_F17&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F18</span> <span class="o">=</span> <span class="s">&quot;KEY_F18&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F19</span> <span class="o">=</span> <span class="s">&quot;KEY_F19&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F20</span> <span class="o">=</span> <span class="s">&quot;KEY_F20&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KPENTER</span> <span class="o">=</span> <span class="s">&quot;KEY_KPENTER&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_RIGHTCTRL</span> <span class="o">=</span> <span class="s">&quot;KEY_RIGHTCTRL&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KPSLASH</span> <span class="o">=</span> <span class="s">&quot;KEY_KPSLASH&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_SYSRQ</span> <span class="o">=</span> <span class="s">&quot;KEY_SYSRQ&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_RIGHTALT</span> <span class="o">=</span> <span class="s">&quot;KEY_RIGHTALT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LINEFEED</span> <span class="o">=</span> <span class="s">&quot;KEY_LINEFEED&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_HOME</span> <span class="o">=</span> <span class="s">&quot;KEY_HOME&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_UP</span> <span class="o">=</span> <span class="s">&quot;KEY_UP&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PAGEUP</span> <span class="o">=</span> <span class="s">&quot;KEY_PAGEUP&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LEFT</span> <span class="o">=</span> <span class="s">&quot;KEY_LEFT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_RIGHT</span> <span class="o">=</span> <span class="s">&quot;KEY_RIGHT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_END</span> <span class="o">=</span> <span class="s">&quot;KEY_END&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_DOWN</span> <span class="o">=</span> <span class="s">&quot;KEY_DOWN&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PAGEDOWN</span> <span class="o">=</span> <span class="s">&quot;KEY_PAGEDOWN&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_INSERT</span> <span class="o">=</span> <span class="s">&quot;KEY_INSERT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_DELETE</span> <span class="o">=</span> <span class="s">&quot;KEY_DELETE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_MACRO</span> <span class="o">=</span> <span class="s">&quot;KEY_MACRO&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_MUTE</span> <span class="o">=</span> <span class="s">&quot;KEY_MUTE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_VOLUMEDOWN</span> <span class="o">=</span> <span class="s">&quot;KEY_VOLUMEDOWN&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_VOLUMEUP</span> <span class="o">=</span> <span class="s">&quot;KEY_VOLUMEUP&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_POWER</span> <span class="o">=</span> <span class="s">&quot;KEY_POWER&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KPEQUAL</span> <span class="o">=</span> <span class="s">&quot;KEY_KPEQUAL&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KPPLUSMINUS</span> <span class="o">=</span> <span class="s">&quot;KEY_KPPLUSMINUS&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PAUSE</span> <span class="o">=</span> <span class="s">&quot;KEY_PAUSE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F21</span> <span class="o">=</span> <span class="s">&quot;KEY_F21&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F22</span> <span class="o">=</span> <span class="s">&quot;KEY_F22&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F23</span> <span class="o">=</span> <span class="s">&quot;KEY_F23&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F24</span> <span class="o">=</span> <span class="s">&quot;KEY_F24&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KPCOMMA</span> <span class="o">=</span> <span class="s">&quot;KEY_KPCOMMA&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LEFTMETA</span> <span class="o">=</span> <span class="s">&quot;KEY_LEFTMETA&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_RIGHTMETA</span> <span class="o">=</span> <span class="s">&quot;KEY_RIGHTMETA&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_COMPOSE</span> <span class="o">=</span> <span class="s">&quot;KEY_COMPOSE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_STOP</span> <span class="o">=</span> <span class="s">&quot;KEY_STOP&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_AGAIN</span> <span class="o">=</span> <span class="s">&quot;KEY_AGAIN&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PROPS</span> <span class="o">=</span> <span class="s">&quot;KEY_PROPS&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_UNDO</span> <span class="o">=</span> <span class="s">&quot;KEY_UNDO&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_FRONT</span> <span class="o">=</span> <span class="s">&quot;KEY_FRONT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_COPY</span> <span class="o">=</span> <span class="s">&quot;KEY_COPY&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_OPEN</span> <span class="o">=</span> <span class="s">&quot;KEY_OPEN&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PASTE</span> <span class="o">=</span> <span class="s">&quot;KEY_PASTE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_FIND</span> <span class="o">=</span> <span class="s">&quot;KEY_FIND&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_CUT</span> <span class="o">=</span> <span class="s">&quot;KEY_CUT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_HELP</span> <span class="o">=</span> <span class="s">&quot;KEY_HELP&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_MENU</span> <span class="o">=</span> <span class="s">&quot;KEY_MENU&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_CALC</span> <span class="o">=</span> <span class="s">&quot;KEY_CALC&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_SETUP</span> <span class="o">=</span> <span class="s">&quot;KEY_SETUP&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_SLEEP</span> <span class="o">=</span> <span class="s">&quot;KEY_SLEEP&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_WAKEUP</span> <span class="o">=</span> <span class="s">&quot;KEY_WAKEUP&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_FILE</span> <span class="o">=</span> <span class="s">&quot;KEY_FILE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_SENDFILE</span> <span class="o">=</span> <span class="s">&quot;KEY_SENDFILE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_DELETEFILE</span> <span class="o">=</span> <span class="s">&quot;KEY_DELETEFILE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_XFER</span> <span class="o">=</span> <span class="s">&quot;KEY_XFER&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PROG1</span> <span class="o">=</span> <span class="s">&quot;KEY_PROG1&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PROG2</span> <span class="o">=</span> <span class="s">&quot;KEY_PROG2&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_WWW</span> <span class="o">=</span> <span class="s">&quot;KEY_WWW&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_MSDOS</span> <span class="o">=</span> <span class="s">&quot;KEY_MSDOS&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_COFFEE</span> <span class="o">=</span> <span class="s">&quot;KEY_COFFEE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_DIRECTION</span> <span class="o">=</span> <span class="s">&quot;KEY_DIRECTION&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_CYCLEWINDOWS</span> <span class="o">=</span> <span class="s">&quot;KEY_CYCLEWINDOWS&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_MAIL</span> <span class="o">=</span> <span class="s">&quot;KEY_MAIL&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_BOOKMARKS</span> <span class="o">=</span> <span class="s">&quot;KEY_BOOKMARKS&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_COMPUTER</span> <span class="o">=</span> <span class="s">&quot;KEY_COMPUTER&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_BACK</span> <span class="o">=</span> <span class="s">&quot;KEY_BACK&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_FORWARD</span> <span class="o">=</span> <span class="s">&quot;KEY_FORWARD&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_CLOSECD</span> <span class="o">=</span> <span class="s">&quot;KEY_CLOSECD&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_EJECTCD</span> <span class="o">=</span> <span class="s">&quot;KEY_EJECTCD&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_EJECTCLOSECD</span> <span class="o">=</span> <span class="s">&quot;KEY_EJECTCLOSECD&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_NEXTSONG</span> <span class="o">=</span> <span class="s">&quot;KEY_NEXTSONG&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PLAYPAUSE</span> <span class="o">=</span> <span class="s">&quot;KEY_PLAYPAUSE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PREVIOUSSONG</span> <span class="o">=</span> <span class="s">&quot;KEY_PREVIOUSSONG&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_STOPCD</span> <span class="o">=</span> <span class="s">&quot;KEY_STOPCD&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_RECORD</span> <span class="o">=</span> <span class="s">&quot;KEY_RECORD&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_REWIND</span> <span class="o">=</span> <span class="s">&quot;KEY_REWIND&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PHONE</span> <span class="o">=</span> <span class="s">&quot;KEY_PHONE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_ISO</span> <span class="o">=</span> <span class="s">&quot;KEY_ISO&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_CONFIG</span> <span class="o">=</span> <span class="s">&quot;KEY_CONFIG&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_HOMEPAGE</span> <span class="o">=</span> <span class="s">&quot;KEY_HOMEPAGE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_REFRESH</span> <span class="o">=</span> <span class="s">&quot;KEY_REFRESH&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_EXIT</span> <span class="o">=</span> <span class="s">&quot;KEY_EXIT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_MOVE</span> <span class="o">=</span> <span class="s">&quot;KEY_MOVE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_EDIT</span> <span class="o">=</span> <span class="s">&quot;KEY_EDIT&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_SCROLLUP</span> <span class="o">=</span> <span class="s">&quot;KEY_SCROLLUP&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_SCROLLDOWN</span> <span class="o">=</span> <span class="s">&quot;KEY_SCROLLDOWN&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KPLEFTPAREN</span> <span class="o">=</span> <span class="s">&quot;KEY_KPLEFTPAREN&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_KPRIGHTPAREN</span> <span class="o">=</span> <span class="s">&quot;KEY_KPRIGHTPAREN&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_INTL1</span> <span class="o">=</span> <span class="s">&quot;KEY_INTL1&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_INTL2</span> <span class="o">=</span> <span class="s">&quot;KEY_INTL2&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_INTL3</span> <span class="o">=</span> <span class="s">&quot;KEY_INTL3&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_INTL4</span> <span class="o">=</span> <span class="s">&quot;KEY_INTL4&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_INTL5</span> <span class="o">=</span> <span class="s">&quot;KEY_INTL5&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_INTL6</span> <span class="o">=</span> <span class="s">&quot;KEY_INTL6&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_INTL7</span> <span class="o">=</span> <span class="s">&quot;KEY_INTL7&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_INTL8</span> <span class="o">=</span> <span class="s">&quot;KEY_INTL8&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_INTL9</span> <span class="o">=</span> <span class="s">&quot;KEY_INTL9&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LANG1</span> <span class="o">=</span> <span class="s">&quot;KEY_LANG1&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LANG2</span> <span class="o">=</span> <span class="s">&quot;KEY_LANG2&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LANG3</span> <span class="o">=</span> <span class="s">&quot;KEY_LANG3&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LANG4</span> <span class="o">=</span> <span class="s">&quot;KEY_LANG4&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LANG5</span> <span class="o">=</span> <span class="s">&quot;KEY_LANG5&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LANG6</span> <span class="o">=</span> <span class="s">&quot;KEY_LANG6&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LANG7</span> <span class="o">=</span> <span class="s">&quot;KEY_LANG7&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LANG8</span> <span class="o">=</span> <span class="s">&quot;KEY_LANG8&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_LANG9</span> <span class="o">=</span> <span class="s">&quot;KEY_LANG9&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PLAYCD</span> <span class="o">=</span> <span class="s">&quot;KEY_PLAYCD&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PAUSECD</span> <span class="o">=</span> <span class="s">&quot;KEY_PAUSECD&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PROG3</span> <span class="o">=</span> <span class="s">&quot;KEY_PROG3&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PROG4</span> <span class="o">=</span> <span class="s">&quot;KEY_PROG4&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_SUSPEND</span> <span class="o">=</span> <span class="s">&quot;KEY_SUSPEND&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_CLOSE</span> <span class="o">=</span> <span class="s">&quot;KEY_CLOSE&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_UNKNOWN</span> <span class="o">=</span> <span class="s">&quot;KEY_UNKNOWN&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_BRIGHTNESSDOWN</span> <span class="o">=</span> <span class="s">&quot;KEY_BRIGHTNESSDOWN&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_BRIGHTNESSUP</span> <span class="o">=</span> <span class="s">&quot;KEY_BRIGHTNESSUP&quot;</span>

        <span class="c"># Add codes for standard buttons</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__codes</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">addCodes</span><span class="p">({</span><span class="bp">self</span><span class="o">.</span><span class="n">KEY_SPACE</span><span class="p">:</span> <span class="s">&#39; &#39;</span><span class="p">,</span>
                       <span class="bp">self</span><span class="o">.</span><span class="n">KEY_MINUS</span><span class="p">:</span> <span class="s">&#39;-&#39;</span><span class="p">,</span>
                       <span class="bp">self</span><span class="o">.</span><span class="n">KEY_APOSTROPHE</span><span class="p">:</span> <span class="s">&quot;&#39;&quot;</span><span class="p">,</span>
                       <span class="bp">self</span><span class="o">.</span><span class="n">KEY_DOT</span><span class="p">:</span> <span class="s">&#39;.&#39;</span><span class="p">,</span>
                       <span class="bp">self</span><span class="o">.</span><span class="n">KEY_TAB</span><span class="p">:</span> <span class="s">&#39;</span><span class="se">\t</span><span class="s">&#39;</span><span class="p">})</span>

        <span class="c"># Add all the numbers to the codes</span>
        <span class="k">for</span> <span class="n">num</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;0&#39;</span><span class="p">,</span> <span class="s">&#39;1&#39;</span><span class="p">,</span> <span class="s">&#39;2&#39;</span><span class="p">,</span> <span class="s">&#39;3&#39;</span><span class="p">,</span> <span class="s">&#39;4&#39;</span><span class="p">,</span> <span class="s">&#39;5&#39;</span><span class="p">,</span> <span class="s">&#39;6&#39;</span><span class="p">,</span> <span class="s">&#39;7&#39;</span><span class="p">,</span> <span class="s">&#39;8&#39;</span><span class="p">,</span> <span class="s">&#39;9&#39;</span><span class="p">]:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">addCode</span><span class="p">(</span><span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&quot;KEY_</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">num</span><span class="o">.</span><span class="n">upper</span><span class="p">()),</span> <span class="n">num</span><span class="p">)</span>

        <span class="c"># Add all lowercase and uppercase letters to codes</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;a&#39;</span><span class="p">,</span> <span class="s">&#39;b&#39;</span><span class="p">,</span> <span class="s">&#39;c&#39;</span><span class="p">,</span> <span class="s">&#39;d&#39;</span><span class="p">,</span> <span class="s">&#39;e&#39;</span><span class="p">,</span> <span class="s">&#39;f&#39;</span><span class="p">,</span> <span class="s">&#39;g&#39;</span><span class="p">,</span> <span class="s">&#39;h&#39;</span><span class="p">,</span> <span class="s">&#39;i&#39;</span><span class="p">,</span> <span class="s">&#39;j&#39;</span><span class="p">,</span> <span class="s">&#39;k&#39;</span><span class="p">,</span>
                    <span class="s">&#39;l&#39;</span><span class="p">,</span> <span class="s">&#39;m&#39;</span><span class="p">,</span> <span class="s">&#39;n&#39;</span><span class="p">,</span> <span class="s">&#39;o&#39;</span><span class="p">,</span> <span class="s">&#39;p&#39;</span><span class="p">,</span> <span class="s">&#39;q&#39;</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">,</span> <span class="s">&#39;s&#39;</span><span class="p">,</span> <span class="s">&#39;t&#39;</span><span class="p">,</span> <span class="s">&#39;u&#39;</span><span class="p">,</span> <span class="s">&#39;v&#39;</span><span class="p">,</span>
                    <span class="s">&#39;w&#39;</span><span class="p">,</span> <span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="s">&#39;y&#39;</span><span class="p">,</span> <span class="s">&#39;z&#39;</span><span class="p">]:</span>
            <span class="n">keyName</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&quot;KEY_</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">key</span><span class="o">.</span><span class="n">upper</span><span class="p">())</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">addCodes</span><span class="p">({</span><span class="n">keyName</span><span class="p">:</span> <span class="n">key</span><span class="p">,</span> <span class="p">(</span><span class="n">keyName</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">MOD_SHIFT</span><span class="p">):</span> <span class="n">key</span><span class="p">})</span>

        <span class="c"># Create a list of the modifiers</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">modifiers</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">mod</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;CTRL&#39;</span><span class="p">,</span> <span class="s">&#39;ALT&#39;</span><span class="p">,</span> <span class="s">&#39;SHIFT&#39;</span><span class="p">,</span> <span class="s">&#39;META&#39;</span><span class="p">]:</span>
            <span class="n">left</span><span class="p">,</span> <span class="n">right</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_modifiers_from_name</span><span class="p">(</span><span class="n">mod</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">modifiers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">left</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">modifiers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">right</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__pressed_modifiers</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c">#define dictionary look up for key press cases</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__keyPressCases</span> <span class="o">=</span> <span class="p">{}</span>

<div class="viewcode-block" id="UserInput.addKey"><a class="viewcode-back" href="../../../../_generated/pyamp_ui_input_userInput.html#pyamp.ui.input.userInput.UserInput.addKey">[docs]</a>    <span class="k">def</span> <span class="nf">addKey</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">callback</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Add a single key to the key press cases. The key can be a tuple</span>
<span class="sd">        where the first argument is the list of keys, or a single key, and the</span>
<span class="sd">        second argument is a list of modifiers. Optionally, is can just be</span>
<span class="sd">        a list of keys, or it can be a single key.</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="c"># Get the combinations and code for this key</span>
        <span class="n">combinations</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_combinations_from_tuple</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>

        <span class="c"># Assign the code to all the combinations</span>
        <span class="k">for</span> <span class="n">selection</span> <span class="ow">in</span> <span class="n">combinations</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__debug</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;Adding key:&quot;</span><span class="p">,</span> <span class="n">selection</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__keyPressCases</span><span class="p">[</span><span class="n">selection</span><span class="p">]</span> <span class="o">=</span> <span class="n">callback</span>
</div>
<div class="viewcode-block" id="UserInput.addKeys"><a class="viewcode-back" href="../../../../_generated/pyamp_ui_input_userInput.html#pyamp.ui.input.userInput.UserInput.addKeys">[docs]</a>    <span class="k">def</span> <span class="nf">addKeys</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">keys</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Add a key to the key press cases. The keys is a dictionary of</span>
<span class="sd">        keys. Each key in the dictionary is a normal tuple form of a key,</span>
<span class="sd">        and the value of the dictionary key is the callback method.</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">keys</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">addKey</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">keys</span><span class="p">[</span><span class="n">key</span><span class="p">])</span>
</div>
<div class="viewcode-block" id="UserInput.addKeyList"><a class="viewcode-back" href="../../../../_generated/pyamp_ui_input_userInput.html#pyamp.ui.input.userInput.UserInput.addKeyList">[docs]</a>    <span class="k">def</span> <span class="nf">addKeyList</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">keys</span><span class="p">,</span> <span class="n">callback</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Add a list of keys mapped to a single function. Keys can be a tuple</span>
<span class="sd">        where the first index the a list of keys, or a single key, and the</span>
<span class="sd">        second index is the list of modifiers. Or it can be a list of keys, and</span>
<span class="sd">        finally it can be just a single key.</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">keys</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">addKey</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">callback</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="UserInput.addCode"><a class="viewcode-back" href="../../../../_generated/pyamp_ui_input_userInput.html#pyamp.ui.input.userInput.UserInput.addCode">[docs]</a>    <span class="k">def</span> <span class="nf">addCode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">code</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Add codes for given key press events. The key can be a tuple</span>
<span class="sd">        where the first index is a list of keys and the second index is a</span>
<span class="sd">        list of modifiers. Or it can be simply a list of keys, or it can</span>
<span class="sd">        be a single key.</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="c"># Get the combinations and code for this key</span>
        <span class="n">combinations</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_combinations_from_tuple</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>

        <span class="c"># Assign the code to all the combinations</span>
        <span class="k">for</span> <span class="n">selection</span> <span class="ow">in</span> <span class="n">combinations</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__debug</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;Assigning code: </span><span class="si">%s</span><span class="s"> to </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">selection</span><span class="p">,</span> <span class="n">code</span><span class="o">.</span><span class="n">__str__</span><span class="p">())</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__codes</span><span class="p">[</span><span class="n">selection</span><span class="p">]</span> <span class="o">=</span> <span class="n">code</span>
</div>
<div class="viewcode-block" id="UserInput.addCodes"><a class="viewcode-back" href="../../../../_generated/pyamp_ui_input_userInput.html#pyamp.ui.input.userInput.UserInput.addCodes">[docs]</a>    <span class="k">def</span> <span class="nf">addCodes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">keys</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Add codes for given key press events. Each key in the keys</span>
<span class="sd">        dictionary can be a tuple where the first index is a list of keys</span>
<span class="sd">        and the second index is a list of modifiers. Or it can be simply a</span>
<span class="sd">        list of keys, or it can be a single key.</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="c"># Add codes for all the keys given</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">keys</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">addCode</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">keys</span><span class="p">[</span><span class="n">key</span><span class="p">])</span>
</div>
<div class="viewcode-block" id="UserInput.handleKeyPress"><a class="viewcode-back" href="../../../../_generated/pyamp_ui_input_userInput.html#pyamp.ui.input.userInput.UserInput.handleKeyPress">[docs]</a>    <span class="k">def</span> <span class="nf">handleKeyPress</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Handle keys that are pressed.&#39;&#39;&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__dev</span><span class="o">.</span><span class="n">poll</span><span class="p">()</span>

        <span class="n">processed</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="n">buttons</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__dev</span><span class="o">.</span><span class="n">buttons</span>

        <span class="c"># Clear all the buttons that are zero from the dictionary</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">buttons</span><span class="o">.</span><span class="n">copy</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">buttons</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">modifiers</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">__pressed_modifiers</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
                <span class="k">del</span> <span class="n">buttons</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>

        <span class="c"># Traverse all the keys in the dictionary</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">buttons</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">buttons</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">modifiers</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__pressed_modifiers</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">__pressed_modifiers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>

            <span class="n">modStr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_key_presses</span><span class="p">(</span><span class="n">buttons</span><span class="o">.</span><span class="n">copy</span><span class="p">(),</span>
                                            <span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__pressed_modifiers</span><span class="p">))</span>

            <span class="c"># Determine if there is a case for this key</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__applyAnyKey</span><span class="p">(</span><span class="n">modStr</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">modStr</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__keyPressCases</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">__keyPressCases</span><span class="p">[</span><span class="n">modStr</span><span class="p">](</span><span class="bp">self</span><span class="o">.</span><span class="n">__get_code</span><span class="p">(</span><span class="n">modStr</span><span class="p">))</span>
                    <span class="n">processed</span> <span class="o">=</span> <span class="bp">True</span>

        <span class="c"># Clear all the buttons from the dictionary</span>
        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">buttons</span><span class="o">.</span><span class="n">copy</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">modifiers</span><span class="p">:</span>
                <span class="k">del</span> <span class="n">buttons</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>

        <span class="n">buttons</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">processed</span>

    <span class="c">##### Private Methods #####</span>
</div>
    <span class="k">def</span> <span class="nf">__applyAnyKey</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modStr</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Determine if there is a mapping for KEY_ANY and if there</span>
<span class="sd">        is then use the callback.</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="n">anyKey</span> <span class="o">=</span> <span class="s">&quot;&lt;</span><span class="si">%s</span><span class="s">&gt;&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_ANY</span>
        <span class="k">if</span> <span class="n">anyKey</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__keyPressCases</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__keyPressCases</span><span class="p">[</span><span class="n">anyKey</span><span class="p">](</span><span class="bp">self</span><span class="o">.</span><span class="n">__get_code</span><span class="p">(</span><span class="n">modStr</span><span class="p">))</span>
            <span class="k">return</span> <span class="bp">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">False</span>

    <span class="k">def</span> <span class="nf">__replace_modifiers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Replace any modifiers with their correct modifier keys.</span>
<span class="sd">        e.g. MOD_SHIFT_LEFT and MOD_SHIFT_RIGHT are replaced with</span>
<span class="sd">        MOD_SHIFT.</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="n">left</span><span class="p">,</span> <span class="n">right</span><span class="p">,</span> <span class="n">both</span><span class="p">,</span> <span class="nb">any</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_modifiers_from_name</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

        <span class="c"># If any or both exists then remove left and right</span>
        <span class="k">if</span> <span class="nb">any</span> <span class="ow">in</span> <span class="n">modifiers</span> <span class="ow">or</span> <span class="n">both</span> <span class="ow">in</span> <span class="n">modifiers</span><span class="p">:</span>
            <span class="c"># Remove left if it exists in the list</span>
            <span class="c"># @todo: make remove all instances of left</span>
            <span class="n">modifiers</span> <span class="o">=</span> <span class="nb">filter</span><span class="p">(</span><span class="n">_NOT_FUNCTION</span><span class="p">(</span><span class="n">left</span><span class="p">),</span> <span class="n">modifiers</span><span class="p">)</span>

            <span class="c"># Remove right if it exists in the list</span>
            <span class="n">modifiers</span> <span class="o">=</span> <span class="nb">filter</span><span class="p">(</span><span class="n">_NOT_FUNCTION</span><span class="p">(</span><span class="n">right</span><span class="p">),</span> <span class="n">modifiers</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">left</span> <span class="ow">in</span> <span class="n">modifiers</span> <span class="ow">and</span> <span class="n">right</span> <span class="ow">in</span> <span class="n">modifiers</span><span class="p">:</span>
            <span class="n">modifiers</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">left</span><span class="p">)</span>
            <span class="n">modifiers</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">right</span><span class="p">)</span>
            <span class="n">modifiers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">both</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__replace_all_modifiers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__replace_modifiers</span><span class="p">(</span><span class="s">&quot;CTRL&quot;</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__replace_modifiers</span><span class="p">(</span><span class="s">&quot;ALT&quot;</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__replace_modifiers</span><span class="p">(</span><span class="s">&quot;SHIFT&quot;</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__replace_modifiers</span><span class="p">(</span><span class="s">&quot;META&quot;</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__check_modifier</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mod</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">mod</span> <span class="ow">in</span> <span class="n">modifiers</span><span class="p">:</span>
            <span class="k">return</span> <span class="s">&quot;&lt;</span><span class="si">%s</span><span class="s">&gt;&quot;</span> <span class="o">%</span> <span class="n">mod</span>

    <span class="k">def</span> <span class="nf">__determine_keys</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Get the list of keys based on a specific key.&#39;&#39;&#39;</span>
        <span class="n">keys</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c"># Handle the alpha numeric case, and all other cases</span>
        <span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_ANY</span><span class="p">:</span>
            <span class="n">keys</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">KEY_ANY</span><span class="p">])</span>
        <span class="k">elif</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_ALPHA_NUMERIC</span><span class="p">:</span>
            <span class="c"># Add all the numeric digits</span>
            <span class="n">keys</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">KEY_0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_2</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_3</span><span class="p">,</span>
                         <span class="bp">self</span><span class="o">.</span><span class="n">KEY_4</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_4</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_6</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_7</span><span class="p">,</span>
                         <span class="bp">self</span><span class="o">.</span><span class="n">KEY_8</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_9</span><span class="p">])</span>

            <span class="c"># Add all the lowercase, and uppercase alphabetic keys</span>
            <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">KEY_A</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_B</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_C</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_D</span><span class="p">,</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_E</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_F</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_G</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_H</span><span class="p">,</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_I</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_J</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_K</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_L</span><span class="p">,</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_M</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_N</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_O</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_P</span><span class="p">,</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_Q</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_R</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_S</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_T</span><span class="p">,</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_U</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_V</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_W</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_X</span><span class="p">,</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">KEY_Y</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_Z</span><span class="p">]:</span>
                <span class="c"># Add the lower case key, then add capital letters</span>
                <span class="c"># with both left and right shift</span>
                <span class="n">keys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
                <span class="n">keys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__combine_keys</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">MOD_LEFTSHIFT</span><span class="p">,</span> <span class="n">key</span><span class="p">]))</span>
                <span class="n">keys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__combine_keys</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">MOD_RIGHTSHIFT</span><span class="p">,</span> <span class="n">key</span><span class="p">]))</span>
        <span class="k">elif</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEY_PUNCTUATION</span><span class="p">:</span>
            <span class="c"># Add unshifted keys, and shifted keys</span>
            <span class="n">marks</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;DOT&#39;</span><span class="p">,</span> <span class="s">&#39;APOSTROPHE&#39;</span><span class="p">,</span> <span class="s">&#39;COMMA&#39;</span><span class="p">,</span> <span class="s">&#39;SEMICOLON&#39;</span><span class="p">,</span> <span class="s">&#39;MINUS&#39;</span><span class="p">]</span>

            <span class="c"># Add all the keys that do not require shift</span>
            <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">marks</span><span class="p">:</span>
                <span class="n">name</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&quot;KEY_</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">key</span><span class="p">)</span>
                <span class="n">keys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

            <span class="c"># Add all the keys that require shift to be pressed</span>
            <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">marks</span><span class="p">:</span>
                <span class="n">name</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&quot;KEY_</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">key</span><span class="p">)</span>
                <span class="n">keys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__combine_keys</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">MOD_LEFTSHIFT</span><span class="p">,</span> <span class="n">name</span><span class="p">]))</span>
                <span class="n">keys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__combine_keys</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">MOD_RIGHTSHIFT</span><span class="p">,</span> <span class="n">name</span><span class="p">]))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">keys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">keys</span>

    <span class="k">def</span> <span class="nf">__get_modifiers_from_name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
        <span class="n">left</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&quot;MOD_LEFT</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="n">right</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&quot;MOD_RIGHT</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="n">both</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&quot;MOD_LEFTRIGHT</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="nb">any</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">&quot;MOD_</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">left</span><span class="p">,</span> <span class="n">right</span><span class="p">,</span> <span class="n">both</span><span class="p">,</span> <span class="nb">any</span>

    <span class="k">def</span> <span class="nf">__get_modifiers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Convert the list of modifier constants into a single string</span>
<span class="sd">        representing the modifier key combination.</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">modifiers</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">type</span><span class="p">(</span><span class="nb">str</span><span class="p">()):</span>
            <span class="n">modifiers</span> <span class="o">=</span> <span class="p">[</span><span class="n">modifiers</span><span class="p">]</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">modifiers</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="nb">type</span><span class="p">(</span><span class="nb">list</span><span class="p">()):</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&quot;modifiers must be a list!&quot;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__replace_all_modifiers</span><span class="p">(</span><span class="n">modifiers</span><span class="p">)</span>

        <span class="n">mods</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
        <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&quot;CTRL&quot;</span><span class="p">,</span> <span class="s">&quot;ALT&quot;</span><span class="p">,</span> <span class="s">&quot;SHIFT&quot;</span><span class="p">,</span> <span class="s">&quot;META&quot;</span><span class="p">]:</span>
            <span class="n">left</span><span class="p">,</span> <span class="n">right</span><span class="p">,</span> <span class="n">both</span><span class="p">,</span> <span class="nb">any</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_modifiers_from_name</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

            <span class="c"># Add the modifiers to the list correctly</span>
            <span class="k">if</span> <span class="nb">any</span> <span class="ow">in</span> <span class="n">modifiers</span><span class="p">:</span>
                <span class="n">mods</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__check_modifier</span><span class="p">(</span><span class="nb">any</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">both</span> <span class="ow">in</span> <span class="n">modifiers</span><span class="p">:</span>
                <span class="n">mods</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__check_modifier</span><span class="p">(</span><span class="n">both</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># Add left and right to the list</span>
                <span class="k">if</span> <span class="n">left</span> <span class="ow">in</span> <span class="n">modifiers</span><span class="p">:</span>
                    <span class="n">mods</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__check_modifier</span><span class="p">(</span><span class="n">left</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>
                <span class="k">elif</span> <span class="n">right</span> <span class="ow">in</span> <span class="n">modifiers</span><span class="p">:</span>
                    <span class="n">mods</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__check_modifier</span><span class="p">(</span><span class="n">right</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">mods</span>

    <span class="k">def</span> <span class="nf">__get_code</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Get the code for the given key.&#39;&#39;&#39;</span>
        <span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__codes</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__codes</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="s">&#39;&#39;</span>

    <span class="k">def</span> <span class="nf">__get_options</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Get the list of options that are present in the modifier</span>
<span class="sd">        list for the given modifier name.</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="n">left</span><span class="p">,</span> <span class="n">right</span><span class="p">,</span> <span class="n">both</span><span class="p">,</span> <span class="nb">any</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_modifiers_from_name</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">any</span> <span class="ow">in</span> <span class="n">modifiers</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="n">left</span><span class="p">,</span> <span class="n">right</span><span class="p">]</span>
        <span class="k">elif</span> <span class="n">left</span> <span class="ow">in</span> <span class="n">modifiers</span> <span class="ow">and</span> <span class="n">right</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">modifiers</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="n">left</span><span class="p">]</span>
        <span class="k">elif</span> <span class="n">right</span> <span class="ow">in</span> <span class="n">modifiers</span> <span class="ow">and</span> <span class="n">left</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">modifiers</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="n">right</span><span class="p">]</span>
        <span class="k">elif</span> <span class="n">left</span> <span class="ow">in</span> <span class="n">modifiers</span> <span class="ow">and</span> <span class="n">right</span> <span class="ow">in</span> <span class="n">modifiers</span> <span class="ow">or</span> \
                <span class="n">both</span> <span class="ow">in</span> <span class="n">modifiers</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="n">both</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="bp">None</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">__get_modifier_permutations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modifierList</span><span class="p">,</span> <span class="n">modList</span><span class="p">,</span> <span class="n">inMods</span><span class="o">=</span><span class="p">[]):</span>
        <span class="sd">&#39;&#39;&#39;Get all the permutations of modifiers present in the</span>
<span class="sd">        modifierList and return them as items in the modList.</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">modifierList</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span>

        <span class="n">modifiers</span> <span class="o">=</span> <span class="n">modifierList</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">mod</span> <span class="ow">in</span> <span class="n">modifiers</span><span class="p">:</span>
            <span class="n">mods</span> <span class="o">=</span> <span class="n">copy</span><span class="p">(</span><span class="n">inMods</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">mod</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">mods</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mod</span><span class="p">)</span>

            <span class="n">rest</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_modifier_permutations</span><span class="p">(</span><span class="n">copy</span><span class="p">(</span><span class="n">modifierList</span><span class="p">),</span>
                                                    <span class="n">modList</span><span class="p">,</span> <span class="n">mods</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">rest</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">modList</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mods</span><span class="p">)</span>

        <span class="k">return</span> <span class="mi">1</span>

    <span class="k">def</span> <span class="nf">__get_key_combinations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">buttons</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Return the list of key combinations that are present in</span>
<span class="sd">        the buttons and list of modifiers.</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="n">key</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
        <span class="n">modList</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">__replace_all_modifiers</span><span class="p">(</span><span class="n">modifiers</span><span class="p">)</span>

        <span class="n">control</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_options</span><span class="p">(</span><span class="s">&#39;CTRL&#39;</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>
        <span class="n">alt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_options</span><span class="p">(</span><span class="s">&#39;ALT&#39;</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>
        <span class="n">shift</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_options</span><span class="p">(</span><span class="s">&#39;SHIFT&#39;</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>
        <span class="n">meta</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_options</span><span class="p">(</span><span class="s">&#39;META&#39;</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>

        <span class="n">modList</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__get_modifier_permutations</span><span class="p">([</span><span class="n">control</span><span class="p">,</span> <span class="n">alt</span><span class="p">,</span> <span class="n">shift</span><span class="p">,</span> <span class="n">meta</span><span class="p">],</span> <span class="n">modList</span><span class="p">)</span>

        <span class="n">modStrings</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">mods</span> <span class="ow">in</span> <span class="n">modList</span><span class="p">:</span>
            <span class="n">modStr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_modifiers</span><span class="p">(</span><span class="n">mods</span><span class="p">)</span>

            <span class="c"># Add any other keys</span>
            <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">buttons</span><span class="p">:</span>
                <span class="n">realKeys</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__determine_keys</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
                <span class="n">strMod</span> <span class="o">=</span> <span class="n">copy</span><span class="p">(</span><span class="n">modStr</span><span class="p">)</span>

                <span class="k">for</span> <span class="n">rk</span> <span class="ow">in</span> <span class="n">realKeys</span><span class="p">:</span>
                    <span class="n">modStr</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">&lt;</span><span class="si">%s</span><span class="s">&gt;&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">strMod</span><span class="p">,</span> <span class="n">rk</span><span class="p">)</span>
                    <span class="n">modStrings</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">modStr</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">modStrings</span>

    <span class="k">def</span> <span class="nf">__get_key_presses</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">buttons</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Get the string formatted for a key press.&#39;&#39;&#39;</span>
        <span class="n">mods</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_modifiers</span><span class="p">(</span><span class="n">modifiers</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">buttons</span><span class="p">:</span>
            <span class="n">mods</span> <span class="o">+=</span> <span class="s">&quot;&lt;</span><span class="si">%s</span><span class="s">&gt;&quot;</span> <span class="o">%</span> <span class="n">key</span>

        <span class="k">return</span> <span class="n">mods</span>

    <span class="k">def</span> <span class="nf">__get_keys_modifiers_from_tuple</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Get the keys and modifiers for the given tuple.&#39;&#39;&#39;</span>
        <span class="c"># Handle the different types of input</span>
        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">type</span><span class="p">(</span><span class="nb">tuple</span><span class="p">()):</span>
            <span class="c"># Get the key codes and modifiers from the tuple</span>
            <span class="n">keys</span> <span class="o">=</span> <span class="n">key</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">modifiers</span> <span class="o">=</span> <span class="n">key</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>

            <span class="c"># Force the key codes and modifiers to be lists</span>
            <span class="n">keys</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__force_list</span><span class="p">(</span><span class="n">keys</span><span class="p">)</span>
            <span class="n">modifiers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__force_list</span><span class="p">(</span><span class="n">modifiers</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">type</span><span class="p">(</span><span class="nb">list</span><span class="p">()):</span>
            <span class="c"># A list of keys, no modifiers</span>
            <span class="n">keys</span> <span class="o">=</span> <span class="n">key</span>
            <span class="n">modifiers</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">type</span><span class="p">(</span><span class="nb">str</span><span class="p">()):</span>
            <span class="c"># A single key, no modifiers</span>
            <span class="n">keys</span> <span class="o">=</span> <span class="p">[</span><span class="n">key</span><span class="p">]</span>
            <span class="n">modifiers</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&quot;Unknown type of key given. Must be a tuple, &quot;</span>
                            <span class="s">&quot;list, or string&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">keys</span><span class="p">,</span> <span class="n">modifiers</span>

    <span class="k">def</span> <span class="nf">__get_combinations_from_tuple</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Get all the combinations of keys and modifiers for the</span>
<span class="sd">        given tuple.</span>

<span class="sd">        &#39;&#39;&#39;</span>
        <span class="n">keys</span><span class="p">,</span> <span class="n">modifiers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_keys_modifiers_from_tuple</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>

        <span class="c"># Grab the combinations for the key and modifiers</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_key_combinations</span><span class="p">(</span><span class="n">keys</span><span class="p">,</span> <span class="n">modifiers</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__combine_keys</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">keys</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Combine all of the keys in the list to be a single key.&#39;&#39;&#39;</span>
        <span class="k">return</span> <span class="s">&#39;&gt;&lt;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">val</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">val</span><span class="p">),</span> <span class="n">keys</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">__force_list</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;Force the object to be a list of strings. If not fail.&#39;&#39;&#39;</span>
        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">type</span><span class="p">(</span><span class="nb">str</span><span class="p">()):</span>
            <span class="k">return</span> <span class="p">[</span><span class="n">obj</span><span class="p">]</span>

        <span class="c"># Ensure it is a list</span>
        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="nb">type</span><span class="p">(</span><span class="nb">list</span><span class="p">()):</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&quot;Object must be a list!&quot;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">obj</span>

</div>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">_KEYBOARD_DEVICE</span> <span class="o">=</span> <span class="s">&quot;/dev/input/event3&quot;</span>
    <span class="n">ui</span> <span class="o">=</span> <span class="n">UserInput</span><span class="p">(</span><span class="n">_KEYBOARD_DEVICE</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">stop</span><span class="p">(</span><span class="n">val</span><span class="p">):</span>
        <span class="k">print</span> <span class="s">&quot;stop:&quot;</span><span class="p">,</span> <span class="n">val</span>

    <span class="n">ui</span><span class="o">.</span><span class="n">addCodes</span><span class="p">({(</span><span class="n">ui</span><span class="o">.</span><span class="n">KEY_SLASH</span><span class="p">,</span> <span class="n">ui</span><span class="o">.</span><span class="n">MOD_SHIFT</span><span class="p">):</span> <span class="s">&#39;?&#39;</span><span class="p">,</span>
                 <span class="p">(</span><span class="n">ui</span><span class="o">.</span><span class="n">KEY_1</span><span class="p">,</span> <span class="n">ui</span><span class="o">.</span><span class="n">MOD_SHIFT</span><span class="p">):</span> <span class="s">&#39;!&#39;</span><span class="p">})</span>
    <span class="n">ui</span><span class="o">.</span><span class="n">addKeyList</span><span class="p">([</span><span class="n">ui</span><span class="o">.</span><span class="n">KEY_ALPHA_NUMERIC</span><span class="p">,</span>
                   <span class="n">ui</span><span class="o">.</span><span class="n">KEY_PUNCTUATION</span><span class="p">,</span>
                   <span class="p">(</span><span class="n">ui</span><span class="o">.</span><span class="n">KEY_SLASH</span><span class="p">,</span> <span class="n">ui</span><span class="o">.</span><span class="n">MOD_SHIFT</span><span class="p">),</span>
                   <span class="p">(</span><span class="n">ui</span><span class="o">.</span><span class="n">KEY_1</span><span class="p">,</span> <span class="n">ui</span><span class="o">.</span><span class="n">MOD_SHIFT</span><span class="p">)],</span> <span class="n">stop</span><span class="p">)</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
            <span class="kn">import</span> <span class="nn">time</span>
            <span class="n">ui</span><span class="o">.</span><span class="n">handleKeyPress</span><span class="p">()</span>
            <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.01</span><span class="p">)</span>
    <span class="k">except</span> <span class="p">(</span><span class="ne">KeyboardInterrupt</span><span class="p">,</span> <span class="ne">SystemExit</span><span class="p">):</span>
        <span class="nb">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../../../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../../../index.html">pyamp v1.2 documentation</a> &raquo;</li>
          <li><a href="../../../index.html" >Module code</a> &raquo;</li>
          <li><a href="../input.html" >pyamp.ui.input</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, Brett Ponsler.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.1.
    </div>
  </body>
</html>